package com.srcptit.trainning.toannt.btvn2;
import java.util.Scanner;
public class Doi_coso {
	public static void doiCoSo(int n,int base){//ham chuyen doi co so.
		if(n>=base) doiCoSo(n / base, base); 
		if(n % base>9) System.out.printf("%c",n%base+55); //vuot qua 9 chuyen sang ki tu chu
		else System.out.print((n % base)); 
		}
	public static int nhap(){ //nhap du lieu
		Scanner input= new Scanner(System.in);
		boolean check= false; int n=0; 
		while(!check){ //yeu cau nguoi nhap dua vao 1 so nguyen
			System.out.print(" ");
			try{ n= input.nextInt(); 
			check= true; 
			}catch(Exception e){ 
				System.out.println("Ban phai nhap so! hay nhap lai..."); 
				input.nextLine(); } }
		return (n); } 
	public static void main(String[] args) { 
		System.out.println("Nhap n");
		int n= nhap();
		System.out.println("Nhap vao co so can chuyen sang b");
		int b= nhap(); 
		System.out.println("So " +n+ " chuyen sang co so " +b+ " thanh: "); 
		doiCoSo(n,b);
		} 

}
